
#include <thread>
#include <chrono>
#include <atomic>
#include "ThreadPool.h"
#include "FlexThreadPool.h"

using namespace Ark;
void Test_FlexThreadPool();

int main()
{
    Test_FlexThreadPool();


    return 0;
}

void Test_ThreadPool()
{
    ThreadPool* pool = new ThreadPool();
    pool->Start(0);
    std::atomic<int> atomic(0);
    for (int i = 0; i < 100; ++i) {
        pool->Post([i, &atomic]() {
            std::this_thread::sleep_for(std::chrono::duration<int>(1));
            printf("%d\n", i);
            atomic++;
        });
    }

    std::this_thread::sleep_for(std::chrono::duration<int>(5));
    pool->Stop();
    printf("total=%d\n", (int)atomic);
}

void Test_FlexThreadPool()
{
    FlexThreadPool* pool = new FlexThreadPool();
    pool->Start(4, 8, 0);
    std::atomic<int> atomic(0);
    for (int i = 0; i < 30; ++i) {
        pool->Post([i, &atomic]() {
            std::this_thread::sleep_for(std::chrono::duration<int>(5));
            printf("%d\n", i);
            atomic++;
        });
    }

    std::this_thread::sleep_for(std::chrono::duration<int>(1000));
    pool->Stop();
    printf("total=%d\n", (int)atomic);
}